<%-- 
    Document   : jspModel
    Created on : Feb 29, 2012, 4:11:44 AM
    Author     : 章哲原
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>密码重置</title>
        <%@include file="/WEB-INF/jspf/top_easyui.jspf" %>
        <script type="text/javascript">
            $(document).ready(function(){
                $('#listUser').datagrid({
                    title:'用户列表', //标题  
                    method:'post',  
                    iconCls:'icon-tedit', //图标  
                    singleSelect:true, //多选  
                    height:360, //高度  
                    width:600, //宽度  
                    fitColumns: true, //自动调整各列，用了这个属性，下面各列的宽度值就只是一个比例。  
                    striped: true, //奇偶行颜色不同  
                    collapsible:true,//可折叠  
                    url:"${contextPath}/user/userList", //数据来源  
                    //                      sortName: 'userNo', //排序的列  
                    //                      sortOrder: 'desc', //倒序  
                    remoteSort: true, //服务器端排序  
                    idField:'id', //主键字段  
                    queryParams:{}, //查询条件  
                    pagination:true, //显示分页  
                    rownumbers:true, //显示行号
                    loadMsg:"正在加载，请稍候...",//远程加载时的提示信息
                    columns:[[
                            {field:'userName',title:'用户名',width:150,sortable:true},
                            {field:'userNo',title:'账号',width:150,sortable:true},
                            {field:'orgName',title:'所属组织机构',width:150,sortable:true},
                            {field:'state',title:'状态',width:150,sortable:true,
                                formatter:function(value,row,index){
                                    if(value=='0'){
                                        return "激活";
                                    }else{
                                        return "冻结";
                                    }
                                }
                            }
                        ]],
                    toolbar:[{
                            id:'resetPwdBt',
                            text:'重置密码',
                            iconCls:'icon-lock-go',
                            handler:function(){
                                var selected = $('#listUser').datagrid('getSelected');
                                if(selected){
                                    $("#rpUserName").text(selected.userName);
                                    $("#rePwdDialog").dialog('open');
                                }
                            }
                        },'-',{
                            id:'btsearch',
                            text:'查询',
                            iconCls:'icon-search',
                            handler:function(){
                                $("#searchDialog").dialog("open");
                                $("input[name=userNo]").focus();
                            }
                        }],
                    onDblClickRow:function(){
                        $("#btinfo").click();
                    },
                    onLoadSuccess:function(){  
                        $('#listUser').datagrid('clearSelections'); //一定要加上这一句，要不然datagrid会记住之前的选择状态，删除时会出问题  
                    }
                });
                var p = $('#listUser').datagrid('getPager');
                $(p).pagination({
                    pageSize: 10,//每页显示的记录条数，默认为10 
                    pageList: [5,10,20,30,40,50],//可以设置每页记录条数的列表 
                    beforePageText: '第',//页数文本框前显示的汉字 
                    afterPageText: '页    共 {pages} 页', 
                    displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
                });
                //添加弹出查询的dialog
                $("#searchDialog").dialog({
                    title:"查询用户",
                    iconCls:"icon-trow",
                    closed:true,
                    width:550,
                    height:140,
                    left:600,
                    top:0,
                    buttons:[{
                            text:'取消',
                            handler:function(){
                                $('#searchDialog').dialog('close');
                            }
                        }]
                });
                //查询
                function doUserSearch(){
                    var params = $('#listUser').datagrid('options').queryParams; //先取得 datagrid 的查询参数  
                    var fields =$('#queryForm').serializeArray(); //自动序列化表单元素为JSON对象  
                    $.each( fields, function(i, field){  
                        params[field.name] = field.value; //设置查询参数 field.name为组件name，field.value为组件值 
                    }); 
                }
                $("#asearch").click(function(){
                    doUserSearch();
                    $('#listUser').datagrid('load');
                });
                //查询清空
                $("#areset").click(function(){
                    $('#queryForm').form('clear');  
                    doUserSearch();
                    $('#listUser').datagrid('load');
                });
                $("#rePwdDialog").dialog({
                    title:"安全验证",
                    iconCls:"icon-lock",
                    closed:true,
                    modal:true,
                    shadow:true,
                    width:260,
                    height:140,
                    buttons:[{
                            text:'确定重置',
                            iconCls:'icon-update',
                            handler:function(){
                                var selected = $('#listUser').datagrid('getSelected');
                                var rpOption={
                                    url:"${contextPath}/user/resetPwd?userId="+selected.id,
                                    type:"POST",
                                    dataType : "json",
                                    success:function(rpr){
                                        if(rpr.rs){
                                            $.messager.alert('友情提示','密码重置成功！', 'info');
                                            $('#rePwdDialog').dialog('close');
                                        }else{
                                            $.messager.alert('友情提示','密码重置失败,请稍后重试！', 'error');
                                        }
                                    }
                                };
                                $("#rePwdForm").ajaxSubmit(rpOption);
                            }
                        },{
                            text:'取消',
                            handler:function(){
                                $('#rePwdDialog').dialog('close');
                            }
                        }]
                });
            });
        </script>
    </head>
    <body>
        <script type="text/javascript">
            $("body").mask({
                maskMsg:"正在初始化，请稍后...",
                timeout:1000,
                opacity:1
            });
        </script>
        <!--        用户表格-->
        <table  id="listUser" > 
        </table>
        <!--        查询框-->
        <div id="searchDialog" class="easyui-dialog" >
            <form id="queryForm" method="post">
                <table>
                    <tr>
                        <td>
                            &nbsp;&nbsp;
                        </td>
                        <td align="right">
                            账号：
                        </td>
                        <td>
                            <input class="normaltext" type="text" name="userNo"/>
                        </td>
                        <td>
                            &nbsp;&nbsp;
                        </td>
                        <td align="right">
                            用户名：
                        </td>
                        <td>
                            <input class="normaltext" type="text" name="userName"/>
                        </td>
                        <td>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                        </td>
                        <td>
                            <a href="Javascript:void(0)" id="asearch" class="easyui-linkbutton" iconCls="icon-search">查 询</a>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;&nbsp;
                        </td>
                        <td align="right">
                            所属机构：
                        </td>
                        <td>
                            <input class="normaltext" type="text" name="orgName"/>
                        </td>
                        <td>
                            &nbsp;&nbsp;
                        </td>
                        <td align="right">
                            状态：
                        </td>
                        <td>
                            <input class="normaltext" type="text" name="state"/>
                        </td>
                        <td>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                        </td>
                        <td>
                            <a href="Javascript:void(0)" id="areset" class="easyui-linkbutton" iconCls="icon-undo">清 空</a>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
        <div id="rePwdDialog" class="easyui-dialog" >
            <form id="rePwdForm" method="post">
                <table>
                    <tr>
                        <td>
                            &nbsp;&nbsp;
                        </td>
                        <td>
                            您当前正在用户名为<span id="rpUserName"  style="color: #0066cc" ></span>的用户<br/>重置密码，请输入当前操作用户的密码：
                        </td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;&nbsp;
                        </td>
                        <td align="center">
                            <input class="normaltext" type="password" name="pwd" id="userPwd" />
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
</html>
